package com.service.merchant.impl;

import com.bean.Merchant;
import com.dao.MerchantMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.service.core.AbstractService;
import com.service.merchant.MerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;

/**
 * Created by lvjianqing on 2017/9/10.
 */
@Service
public class MerchantServiceImpl extends AbstractService<Merchant,Integer> implements MerchantService {
    @Autowired
    private MerchantMapper merchantMapper;


    @Override
    public Page findByPage(int pageNum, int pageSize, HashMap<String, Object> paraMap) {
        PageHelper.startPage(pageNum, pageSize);
        Page page = (Page) merchantMapper.findAll(paraMap);
        return page;
    }

    @Override
    public Merchant findMerchantById(Integer id) {
        if(id!=null){
            return merchantMapper.selectByPrimaryKey(id);
        }
        return null;
    }

    @Override
    public void saveMerchant(Merchant merchant) {
        if(merchant!=null){
            if(merchant.getId()!=null){
                merchantMapper.updateByPrimaryKeySelective(merchant);
            }else{
                merchant.setCreatetime(new Date());
                merchantMapper.insertSelective(merchant);
            }
        }
    }
}
